﻿using System;
using System.Collections.Generic;
using System.IO;

namespace GeneticAlgorithm
{
    public class Parser
    {
        public static List<Item> Parse()
        {
            var list = new List<Item>();
            using (var streamReader = new StreamReader("database.txt"))
            {
                string data;
                
                while ((data = streamReader.ReadLine()) != null)
                {
                    var item = new Item();
                    var stringSeparators = new string[] { "::" };
                    var @params = data.Split(stringSeparators, StringSplitOptions.None);
                    item.Name = @params[0];
                    item.Price = int.Parse(@params[1]);
                    item.Count = int.Parse(@params[2]);
                    item.Margin = int.Parse(@params[4]);
                    item.Category = int.Parse(@params[5]);
                    list.Add(item);
                }
            }
            return list;
        }
    }
}
